#!/usr/bin/env python
"""

   filter_strings.py

        filters     
        specified in the following format "gap_pos:gap_len|gap_pos:gap_len|gap_pos:gap_len"



   Copyright (C) 2007 Leo Goodstadt

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; version 2
   of the License

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""


import string
def Translator(frm='', to='', delete='', keep=None):
    allchars = string.maketrans('','')
    if len(to) == 1:
        to = to * len(frm)
    trans = string.maketrans(frm, to)
    if keep is not None:
        delete = allchars.translate(allchars, keep.translate(allchars, delete))
    def callable(s):
        return s.translate(trans, delete)
    return callable


if __name__ == "__main__":
    rand_str="""
        s distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""
    trans = Translator(keep="AGCT-.HMRWY")
    print trans (rand_str)
    trans = Translator(keep= "AGCT")
    print trans(rand_str)
    trans = Translator(delete= string.lowercase + " \n" + string.punctuation)
    print trans(rand_str)
    trans = Translator(frm="agct-.hmrwyn", to="AGCT-.HMRWYN", keep="agcthmrwynAGCT-.HMRWYN")
    print ">>", trans(rand_str)
    trans = Translator(keep="agcthmrwynAGCT-.HMRWYN")
    print ">>", trans(rand_str)

